package com.mrd.gtimp.service.impl;

import com.mrd.exception.QueryException;
import com.mrd.framework.ui.filter.Filter;
import com.mrd.framework.ui.filter.FilterGroupOption;
import com.mrd.framework.ui.filter.SearchRule;
import com.mrd.framework.ui.filter.SearchRuleOption;
import com.mrd.gtimp.base.entity.Company;
import com.mrd.gtimp.base.service.CompanyBiz;
import com.mrd.gtimp.service.IDataInitService;
import com.mrd.gtimp.service.dto.ShipCompanyData;

import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;
import javax.jws.WebService;

/**
 * @author luob
 */

@WebService(endpointInterface = "com.mrd.gtimp.service.IDataInitService",
        serviceName = "DataInitService")
public class DataInitServiceImpl implements IDataInitService {

    @Resource
    private CompanyBiz companyBiz;

    @Override
    public List<ShipCompanyData> initShipCompany() throws RemoteException, QueryException {
        List<ShipCompanyData> resultList = new ArrayList<ShipCompanyData>();

        Filter filters = new Filter();
        filters.setGroupOp(FilterGroupOption.AND);
        SearchRule rule = new SearchRule("type", SearchRuleOption.eq, "SC");
        filters.addRule(rule);
        int count = companyBiz.findEntityCount(filters);
        List<Company> dataResultList = companyBiz.findEntityByFilter(0, count, filters, null);

        for (Company c : dataResultList) {
            ShipCompanyData data = new ShipCompanyData();
            data.setID(c.getId());
            data.setNAME(c.getName());
            resultList.add(data);
        }
        return resultList;
    }

    public void setCompanyBiz(CompanyBiz companyBiz) {
        this.companyBiz = companyBiz;
    }

}
